#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:studentController.py
# author:Jackiex
# datetime:2023/5/18 15:36
# software: PyCharm

"""
this is function  description 
"""

import datetime

from ..models.studentModel import Student
from . import Session
from ..utils.loggins import loggings


class StudentController(Student):

    # add
    @classmethod
    def add(cls, **kwargs):
        session = Session()
        try:
            model = Student(
                autoID=kwargs.get('autoID'),
                studentID=kwargs.get('studentID'),
                name=kwargs.get('name'),
                classID=kwargs.get('classID'),
                age=kwargs.get('age'),
                agenda=kwargs.get('agenda'),
                isDelete=kwargs.get('isDelete'),
                addTime=kwargs.get('addTime'),

            )
            session.add(model)
            session.commit()

            # 构造返回数据
            results = {
                'add_time': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                'autoID': model.autoID,

            }
            return {'code': 200, 'message': "ok!", 'data': results}

        except Exception as e:
            session.rollback()
            loggings.exception(1, e)
            return {'code': 200, 'message': "ok", 'data': {'error': str(e)}}
        finally:
            session.close()

    # get
    @classmethod
    def get(cls, **kwargs):
        pass

    # delete
    @classmethod
    def delete(cls, **kwargs):
        pass

        # update

    @classmethod
    def update(cls, **kwargs):
        pass

